<!--
  * 任务执行日志 员工
-->
<template>
  <div>
    <div class="header">
      <div>
        <a-row class="smart-query-form-row">
        用户地址：
        <a-input style="width: 200px" v-model:value="queryForm.userCertAddress" placeholder="输入用户地址" />
        校验状态：
        <DictSelectType :service-id="SERVICE_ID_ENUM.DICTIONARY.value" :dcit-type="DICT_TYPE_ENUM.ADDR_STATE.value" v-model:value="queryForm.state" width="120px" />
        复核状态：
        <DictSelectType :service-id="SERVICE_ID_ENUM.DICTIONARY.value" :dcit-type="DICT_TYPE_ENUM.ANALYSIS_TYPE.value" v-model:value="queryForm.analysisType" width="120px" />
        匹配类型：
        <DictSelectType :service-id="SERVICE_ID_ENUM.DICTIONARY.value" :dcit-type="DICT_TYPE_ENUM.MATCH_TYPE.value" v-model:value="queryForm.matchType" width="120px" />
        <a-button class="button-style" type="primary" @click="queryTaskDetail">搜索</a-button>
        <a-button class="button-style" type="default" @click="resetQueryTaskDetail">重置</a-button>
        </a-row>
      </div>
    </div>
    <a-table
      :loading="tableLoading"
      :dataSource="tableData"
      :columns="columns"
      :pagination="false"
      rowKey="id"
      size="small"
      bordered
    >
    </a-table>
    <div class="smart-query-table-page">
      <a-pagination
        showSizeChanger
        showQuickJumper
        show-less-items
        :pageSizeOptions="PAGE_SIZE_OPTIONS"
        :defaultPageSize="queryForm.pageSize"
        v-model:current="queryForm.pageIndex"
        v-model:pageSize="queryForm.pageSize"
        :total="total"
        @change="queryTaskDetail"
        @showSizeChange="queryTaskDetail"
        :show-total="showTableTotal"
      />
    </div>
  </div>
</template>
<script setup lang="ts">
  import { message, Modal } from 'ant-design-vue';
  import _ from 'lodash';
  import { reactive, ref, watch, onMounted } from 'vue';
  import { asApi } from '/@/api/addrstandard/as-api'
  import { PAGE_SIZE, PAGE_SIZE_OPTIONS, showTableTotal } from '/@/constants/common-const';
  import { smartSentry } from '/@/lib/smart-sentry';
  import { useRoute } from 'vue-router';
  import { SERVICE_ID_ENUM,DICT_TYPE_ENUM } from '/@/constants/system/cache-service-id-const';
  import DictSelectType from '/@/components/cache/dict-select-type.vue'

  const columns = reactive([
    {
      title: '用户地址',
      dataIndex: 'userCertAddress',
      // width: 150,
    },
    {
      title: '字典地址',
      dataIndex: 'dictCertAddress',
      // width: 150,
    },
    {
      title: '楼盘',
      dataIndex: 'communityName',
      width: 120,
      ellipsis: true,
    },
    {
      title: '楼栋全称',
      dataIndex: 'buildingName',
      width: 120,
      ellipsis: true,
    },
    {
      title: '门牌号',
      dataIndex: 'buildingAddr',
      width: 120,
      ellipsis: true,
    },
    {
      title: '楼栋号',
      dataIndex: 'buildingNum',
      width: 120,
      ellipsis: true,
    },
    {
      title: '单元号',
      dataIndex: 'unitNum',
      width: 80,
      ellipsis: true,
    },
    {
      title: '房号',
      dataIndex: 'houseNumber',
      width: 80,
      ellipsis: true,
    },
    {
      title: '复核状态',
      dataIndex: 'analysisName',
      width: 80,
    },
    {
      title: '匹配类型',
      dataIndex: 'matchName',
      width: 80,
    },
    {
      title: '省',
      dataIndex: 'provinceName',
      width: 80,
    },
    {
      title: '市',
      dataIndex: 'cityName',
      width: 80,
      ellipsis: true,
    },
    {
      title: '区/县',
      dataIndex: 'districtName',
      width: 80,
      ellipsis: true,
    },
  ]);

  // --------------------------- 查询 ---------------------------

  const defaultQueryForm = {
    pageIndex: 1,
    pageSize: PAGE_SIZE,
    taskId:undefined,
    userCertAddress:undefined,
    analysisType:undefined,
    state:undefined,
    matchType:undefined,
  };

  // 查询表单
  const route = useRoute();
  const queryForm = reactive({ ...defaultQueryForm });
  const total = ref(0);
  const tableData = ref([]);
  const tableLoading = ref(false);

  let taskId=ref();

  onMounted(() => {
    if (route.query.taskId) {
      taskId.value = route.query.taskId;
      queryTaskDetail();
    }
  });

  function resetQueryTaskDetail() {
    queryTaskDetail();
  }

  async function queryTaskDetail() {
    try {
      tableLoading.value = true;
    
      queryForm.taskId = taskId;
      let res = await asApi.detailPageQuery(queryForm);
      if(res.success){
        tableData.value = res.data.data;
        total.value = res.data.total;
      }else{
        message.error(res.message);
      }
    } catch (e) {
      smartSentry.captureError(e);
    } finally {
      tableLoading.value = false;
    }
  }
</script>

<style scoped lang="less">
  .header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 20px 0;
  }

  .button-style {
    margin: 0 10px;
  }
</style>
